// V-backend/src/models/Video.js
module.exports = (sequelize, DataTypes) => {
  const Video = sequelize.define('Video', {
    video_id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      field: 'video_id'
    },
    anchor_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      field: 'anchor_id'
    },
    video_title: {
      type: DataTypes.STRING(200),
      allowNull: false,
      field: 'video_title'
    },
    video_description: {
      type: DataTypes.TEXT,
      allowNull: true,
      field: 'video_description'
    },
    video_url: {
      type: DataTypes.STRING(255),
      allowNull: true,
      field: 'video_url'
    },
    cover_image: {
      type: DataTypes.STRING(255),
      allowNull: true,
      field: 'cover_image'
    },
    video_settings: {
      type: DataTypes.TEXT,
      allowNull: true,
      field: 'video_settings'
    },
    video_click_count: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
      field: 'video_click_count'
    },
    category: {
      type: DataTypes.STRING(50),
      allowNull: true,
      field: 'category'
    },
    status: {
      type: DataTypes.TINYINT,
      defaultValue: 1,
      field: 'status'
    },
    created_at: {
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW,
      field: 'created_at'
    }
  }, {
    tableName: 'v_video',
    timestamps: false,
    underscored: true
  });

  Video.associate = function(models) {
    Video.belongsTo(models.Anchor, {
      foreignKey: 'anchor_id',
      as: 'anchor'
    });
  };

  return Video;
};